package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.exceptions.NotEnoughFundsException;

/**
 * Created by zurdan on 14.11.14.
 * E-mail: Zurdanium@gmail.com
 */
public class SavingsAccount extends AbstractAccount {

    public SavingsAccount(final double amount) {
        super(amount);
    }

    @Override
    protected void doDeposit(final double amount) {
        setBalance(getBalance() + amount);
    }

    @Override
    protected void doWithdraw(final double amount) throws NotEnoughFundsException {
        if (!isMoneyEnough(amount)) {
            throw new NotEnoughFundsException(maximumAmountToWithdraw());
        }
        setBalance(getBalance() - amount);
    }

    @Override
    public double maximumAmountToWithdraw() {
        return getBalance();
    }

    @Override
    public String toString() {
        return "SavingAccount{" +
                "balance=" + decimalValue() +
                '}';
    }
}
